# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>

_pkgname=SolidPython
pkgname=python-solidpython
pkgver=1.1.3
pkgrel=3
# missing tag for 1.1.3: https://github.com/SolidCode/SolidPython/issues/202
_commit=0a4f539c31a25df52a42bab2ceeffafd45596f73
pkgdesc='Python frontend for solid modelling that compiles to OpenSCAD'
arch=('any')
url='https://github.com/SolidCode/SolidPython'
license=('LGPL2.1')
depends=('python-euclid3' 'python-prettytable' 'python-ply' 'python-pypng' 'python-setuptools')
makedepends=('git' 'python-build' 'python-installer' 'python-poetry-core' 'python-wheel')
source=(
  "git+https://github.com/SolidCode/SolidPython#commit=$_commit"
  0001-Switch-to-correct-PEP517-build-system.patch
  0002-Add-setuptools-to-dependencies.patch
)
sha512sums=('SKIP'
            '696a2ff91c898a46072d1f766f5be98ba98024d87095c535cec8488cf78a1e629d2311c80e34f095bb2f7d36396bd834c149c2a107f09023362c505b568b8b27'
            'b16fec04ec3c28d7f2f83fb956c7a042ee749df5c1977b079a1bd162c8c644449c5a1f50b83fd2a1a1debe77adaff01511cf0915e0e3c46d2b08cc17a1f140a0')

prepare() {
  # switch to proper PEP517 build-system and fix direct dependencies:
  # https://github.com/SolidCode/SolidPython/pull/203
  patch -Np1 -d $_pkgname -i ../0001-Switch-to-correct-PEP517-build-system.patch
  patch -Np1 -d $_pkgname -i ../0002-Add-setuptools-to-dependencies.patch
}

build() {
  cd $_pkgname

  python -m build --wheel --no-isolation
}

check() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_pkgname
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$site_packages:$PYTHONPATH"

  python -m unittest discover -vs solid/test/
}

package() {
  cd $_pkgname

  python -m installer --destdir="$pkgdir" dist/*.whl
}
